-- <nowiki>
local T = require('Module:Tool')

local slotChampion = require('Module:Data/Slot/Champion')
local slotGlossary = require('Module:Data/Slot/Glossary')

local Value = {}

function Value.champion(args)
    args = T.parseArgs(args)

    local slotRaw = args.slot or args[1]

    if tonumber(slotRaw) ~= nil then
        slotRaw = tonumber(slotRaw)
    end

    local slot = slotChampion[slotRaw]

    if slot == nil then
        return T.error('[Value.champion().slot] is Nil: ' .. T.parseErrorValue(slotRaw))
    end

    local champion = require('Module:Data/Champion/' .. slot)

    if champion == nil then
        return T.error('[Value.champion().champion] is Nil: ' .. T.parseErrorValue(slot))
    end

    local key = args.key or args[2]

    if key == nil then
        return T.error('[Value.champion().key] is not String: ' .. T.parseErrorValue(key))
    end

    if key == '~' then
        return champion
    end

    return T.getter(champion, key)
end

function Value.glossary(args)
    args = T.parseArgs(args)

    local slotRaw = args.slot or args[1]

    if type(slotRaw) == 'string' then
        slotRaw = slotRaw:gsub('^%l', string.upper)
    end

    local slot = slotGlossary[slotRaw]

    if slot == nil then
        return T.error('[Value.glossary().slot] is Nil: ' .. T.parseErrorValue(slotRaw))
    end

    local glossary = require('Module:Data/Glossary/' .. slot)

    if glossary == nil then
        return T.error('[Value.glossary().glossary] is Nil: ' .. T.parseErrorValue(slot))
    end

    if glossary.icon == true then
        glossary.icon = 'Icon-Glossary-' .. slot
    end

    local key = args.key or args[2]

    if key == nil then
        return T.error('[Value.glossary().key] is not String: ' .. T.parseErrorValue(key))
    end

    local value = T.getter(glossary, key)

    if key == '~' then
        return glossary
    end

    return value
end

return Value
-- </nowiki>
-- [[Category:Module]][[Category:Module/Function]]
